package threadLock.lock.AQS;

import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * 线程安全的并发队列 非阻塞 无界
 */
public class ConcurrentLinkedQueueTest {

    private static volatile ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();

    public static void main(String[] args) throws InterruptedException {
        Thread threadOne = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                queue.offer(i+"");
            }
        },"threadOne");

        Thread threadTow = new Thread(() -> {
            for (int i = 5; i < 10; i++) {
                queue.offer(i+"");
            }
        },"threadTow");

        threadOne.start();
        threadTow.start();
        Thread.sleep(1000);

        queue.forEach(item-> {
            System.out.println("main thread read queue "+item);
        });
    }
}
